using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_CategoryList : System.Web.UI.UserControl
{
   /*
    protected void Page_Load(object sender, EventArgs e)
    {

            // Obtain the ID of the selected department
            string departmentId = Request.QueryString["DepartmentID"];
            // Continue only if DepartmentID exists in the query string
            if (departmentId != null)
            {
                // Catalog.GetCategoriesInDepartment returns a DataTable
                // object containing category data, which is displayed by the DataList
                list.DataSource =
                CatalogAccess.GetCategoriesInDepartmentWithNumberOfProducts(departmentId);
                // Needed to bind the data bound controls to the data source
                list.DataBind();
                // Make space for the next control

            }

        }
    */
    private int _categoryID = -1;

    public int CategoryID
    {
        get
        {
            if (Request.QueryString["CategoryID"] != null)
            {
                this._categoryID = int.Parse(Request.QueryString["CategoryID"]);
            }
            return this._categoryID;
        }
        set { _categoryID = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        // Obtain the ID of the selected department
        string departmentId = Request.QueryString["DepartmentID"];
        // Continue only if DepartmentID exists in the query string
        if (departmentId != null)
        {
            // Catalog.GetCategoriesInDepartment returns a DataTable
            // object containing category data, which is displayed by the DataList
            list.DataSource = CatalogAccess.GetCategoriesInDepartmentWithNumberOfProducts(departmentId);
            // Needed to bind the data bound controls to the data source
            list.DataBind();
            // Make space for the next control

        }
    }

    protected void list_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.DataItem as DataRowView) != null)
        {
            if (((int)(e.Item.DataItem as DataRowView).Row.ItemArray[0]) == this.CategoryID)
            {
                list.SelectedIndex = e.Item.ItemIndex;
            }
        }
    }
   
}
